/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.Business.GuildEntryStat
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-08-02 -- Cliff Simpkins: Initial Version with properties and constructors
 * 2007-09-23 -- Cliff Simpkins: Added the Stat_Value interpreted property
 **********************************************************************
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using DotNetWarcraft.Common;

namespace DotNetWarcraft.WoWGuildRoster.Business {
  /// <summary>
  /// Stat entry that contains information about a GuildEntry. This is a generic class 
  ///   that can contain multiple types of information. The exact type of content is
  ///   determined by the enumeration.
  /// </summary>
  public class GuildEntryStat {
  #region Private Members
    protected int _charstat_id;
    protected int _char_id;

    protected int _stat_type;
    protected String _stat_group;
    protected String _stat_entry;
    protected int _stat_value_int;
    protected double _stat_value_dec;
    protected String _stat_value_str;

    protected DateTime _last_load_date;
    protected int _last_load_id;
  #endregion
  #region Public Properties
    public int CharStat_ID {
      get { return _charstat_id; }
      set { _charstat_id = value; }
    }
    public int Char_ID {
      get { return _char_id; }
      set { _char_id = value; }
    }

    public int Stat_Type {
      get {return _stat_type;}
      set {_stat_type = value;}
    }
    public WarcraftStatTypes Stat_Type_Enum {
      get {
        return WGRConstants.WowStatType_Enum(this.Stat_Type);
      }
      set {
        this.Stat_Type = WGRConstants.WowStatType_Int(value);
      }
    }

    public String Stat_Group {
      get {return _stat_group;}
      set {_stat_group = value;}
    }
    public String Stat_Entry {
      get {return _stat_entry;}
      set {_stat_entry = value;}
    }
    public int Stat_Value_int {
      get { return _stat_value_int; }
      set { _stat_value_int = value; }
    }
    public double Stat_Value_dec {
      get {
        return _stat_value_dec;
      }
      set {
        _stat_value_dec = value;
      }
    }
    public String Stat_Value_str {
      get { return _stat_value_str; }
      set { _stat_value_str = value; }
    }

    public DateTime Last_Load_Date {
      get { return _last_load_date; }
      set { _last_load_date = value; }
    }
    public int Last_Load_ID {
      get { return _last_load_id; }
      set { _last_load_id = value; }
    }
  #endregion

  #region Constructors
    public GuildEntryStat() : base() {
      this.CharStat_ID = -1;
      this.Char_ID = -1;
      this.Stat_Type_Enum = WarcraftStatTypes.Unknown;

      this.Stat_Group = "";
      this.Stat_Entry = "";
      this.Stat_Value_int = -1;
      this.Stat_Value_dec = -1.0;
      this.Stat_Value_str = "";

      this.Last_Load_Date = DateTime.MinValue;
      this.Last_Load_ID = -1;
    }
    public GuildEntryStat(int charID, int statType, String statGroup, String statEntry, int valueInt, double valueDec, String valueStr)
      : this() {
      this.CharStat_ID = -1;
      this.Char_ID = charID;
      this.Stat_Type = statType;

      this.Stat_Group = statGroup;
      this.Stat_Entry = statEntry;
      this.Stat_Value_int = valueInt;
      this.Stat_Value_dec = valueDec;
      this.Stat_Value_str = valueStr;
      this.Last_Load_Date = DateTime.UtcNow;
    }

    public GuildEntryStat(int charID, int statType, String statGroup, String statEntry, int valueInt, double valueDec, String valueStr, int loadID) 
      : this(charID, statType, statGroup, statEntry, valueInt, valueDec, valueStr) {
      this.Last_Load_ID = loadID;
    }

    public GuildEntryStat(int charID, int statType, String statGroup, String statEntry, int valueInt)
      : this(charID, statType, statGroup, statEntry, valueInt, -1.0, "") {
    }

    public GuildEntryStat(int charID, int statType, String statGroup, String statEntry, int valueInt, String valueStr)
      : this(charID, statType, statGroup, statEntry, valueInt, -1.0, valueStr) {
    }

    public GuildEntryStat(int charID, int statType, String statGroup, String statEntry, double valueDec)
      : this(charID, statType, statGroup, statEntry, -1, valueDec, "") {
    }

    public GuildEntryStat(int charID, int statType, String statGroup, String statEntry, String valueStr)
      : this(charID, statType, statGroup, statEntry, -1, -1.0, valueStr) {
    }

    public GuildEntryStat(DataRow rosterSrc) : base() {
      this.CharStat_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["charstat_id"]);
      this.Char_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["char_id"]);
      this.Stat_Type = SqlDataUtils.RetrieveDbInt(rosterSrc["stat_type"]);

      this.Stat_Group = SqlDataUtils.RetrieveDbString(rosterSrc["stat_group"]);
      this.Stat_Entry = SqlDataUtils.RetrieveDbString(rosterSrc["stat_entry"]);
      this.Stat_Value_int = SqlDataUtils.RetrieveDbInt(rosterSrc["stat_value_int"]);
      this.Stat_Value_dec = SqlDataUtils.RetrieveDbDec(rosterSrc["stat_value_dec"]);
      this.Stat_Value_str = SqlDataUtils.RetrieveDbString(rosterSrc["stat_value_str"]);

      this.Last_Load_Date = SqlDataUtils.RetrieveDbDate(rosterSrc["last_load_date"]);
      this.Last_Load_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["last_load_id"]);
    }
  #endregion

  #region Interpreted Properties
    public String Stat_Value {
      get {
        if (this.Stat_Value_str.Trim() != "" &&
          this.Stat_Value_str.ToLower().Trim() != this.Stat_Entry.ToLower().Trim()) {
          return this.Stat_Value_str.Trim();
        } else if (this.Stat_Value_int != -1) {
          return this.Stat_Value_int.ToString();
        } else if (this.Stat_Value_dec != -1.0) {
          return this.Stat_Value_dec.ToString();
        } else
          return "";
      }
    }
  #endregion
  #region Public Methods
  #endregion
  }
}
